//
//  MainViewController.m
//  ConscienceWorldPorject
//
//  Created by 孙海琛 on 2019/11/22.
//  Copyright © 2019 孙海琛. All rights reserved.
//

#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.edgesForExtendedLayout = NO;
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorFromHexCode:@"F2F2F2"];
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    [self navStauts40];
}

#pragma mark -- 状态栏顶部包含录音热点等状态栏高度为40时 布局解决
- (void)navStauts40
{
    if ([[UIApplication sharedApplication] statusBarFrame].size.height == 40) {
        for (UIView *aView in self.navigationController.navigationBar.subviews) {
            if ([@[@"_UIBarBackground"] containsObject:NSStringFromClass([aView class])]) {
                UIView *subV = aView.subviews[0];
                subV.frame = CGRectMake(0, 0, SCREEN_WIDTH, 64);
            }
        }
    }
}


#pragma mark -- 重写push方法
- (void)pushToNextViewController:(NSString*)ControllerName obj:(id)obj
{
    [self pushToNextViewController:ControllerName obj:obj hideTabbar:nil];
}
- (void)pushToNextViewController:(NSString *)ControllerName obj:(id)obj hideTabbar:(BOOL)isHide{
    [self pushToNextViewController:ControllerName obj:obj hideTabbar:isHide needAnimated:YES];
}
- (void)pushToNextViewController:(NSString *)ControllerName obj:(id)obj hideTabbar:(BOOL)isHide needAnimated:(BOOL)isAnimated{
    Class class = NSClassFromString(ControllerName);
    MainViewController *destinationController = [[class alloc] init];
    [destinationController setObj:obj];
    if (isHide) {
        destinationController.hidesBottomBarWhenPushed = YES;
    }else
    {
        destinationController.hidesBottomBarWhenPushed = NO;
    }
    [self.navigationController pushViewController:destinationController animated:isAnimated];
}
- (void)presentToViewController:(NSString *)ControllerName obj:(id)obj{
    Class class = NSClassFromString(ControllerName);
    MainViewController *destinationController = [[class alloc] init];
    [destinationController setObj:obj];
    [destinationController setHidesBottomBarWhenPushed:YES];
    UINavigationController *nav = [[UINavigationController alloc]
                                   initWithRootViewController:destinationController];
    [self.navigationController presentViewController:nav animated:YES completion:nil];
}


#pragma mark -- 设置状态栏颜色
- (void)setStatusBarBackgroundColor:(UIColor *)color {
    
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
}

#pragma mark -- 改变状态栏字体颜色
- (void)changeBarWhiteOrBlack:(BOOL)isWhite
{
    [UIApplication sharedApplication].statusBarStyle = isWhite==YES?UIStatusBarStyleLightContent:UIStatusBarStyleDefault;
}
#pragma mark -- tableView复用
-(UITableViewCell *)tableview:(UITableView *)tableView cellWithIdentifier:(NSString *)cell
{
    UITableViewCell *cells = [tableView dequeueReusableCellWithIdentifier:cell];
    if (cells == nil) {
        cells = [[[NSBundle mainBundle] loadNibNamed:cell owner:self options:nil]lastObject];
    }
    return cells;
}

@end
